<style lang="less">
  #div_truck_load_driver_cooperation_truck_bellwether_sy {
  }
</style>

<template>
  <div id="div_truck_load_driver_cooperation_truck_bellwether_sy">
    <el-row class="f-mt f-wa f-mb10">
      <el-col :span="24">
        <ue-search-bar ref="ueSearchBar" v-model="searchForm" :data="querys" label-width="120px">
        </ue-search-bar>
      </el-col>
      <el-col :span="24">
        <el-button type="primary" class="f-wa f-fr f-ml10 f-mr20" @click="$refs.ueSearchBar.reset()">重置</el-button>
        <el-button type="primary" class="f-wa f-fr f-ml10" @click="searchCooperationTruckBellwetherToFilters">查询
        </el-button>
      </el-col>
    </el-row>
    <el-table :data="truckBellwetherTableDate" border style="width: 100%">
      <el-table-column prop="realName" label="姓名姓名">
      </el-table-column>
      <el-table-column prop="phone" label="联系手机">
      </el-table-column>
      <el-table-column prop="lifetimeSales" label="合作订单数">
      </el-table-column>
      <el-table-column prop="latelyCooperationTime" label="最近合作日期">
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="currentPage"
      :page-size="pageSize"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      layout="total,sizes,prev,pager,next,jumper"
      :total="total" style="float: right">
    </el-pagination>
  </div>
</template>

<script>
import { objToFilter, isEmpty } from '../../lib/util.js';
import { searchCooperateBellwethers } from '../../api/v3/TruckLoadDriver.js';

export default {
  props: {
    cooperationTruckBellwether: {
      type: Object
    },
    isRefresh: {
      type: Boolean
    }
  },
  watch: {
    cooperationTruckBellwether (val) {
      this.cooperationTruckBellwetherModel = val;
      this.searchCooperationTruckBellwetherToFilters();
    },
    isRefresh (val) {
      if (val) {
        this.searchCooperationTruckBellwetherToFilters();
      }
    }
  },
  data () {
    return {
      cooperationTruckBellwetherModel: {},
      searchForm: {},
      truckBellwetherTableDate: [],
      currentPage: 1,
      pageSize: 10,
      total: 0
    };
  },
  methods: {
    searchCooperationTruckBellwetherToFilters () {
      let phone = this.cooperationTruckBellwetherModel.driverPhone;
      if (isEmpty(phone)) {
        return;
      }
      let filters = 'EQ_driverPhone=' + phone + ';';
      let ob = Object.assign({}, this.searchForm);
      filters = filters + objToFilter(ob);
      this.searchCooperationTruckBellwetherByDrive(filters);
    },
    searchCooperationTruckBellwetherByDrive (filters) {
      console.log(filters);
      searchCooperateBellwethers({
        filters: filters,
        sort: '',
        page: this.currentPage - 1,
        size: this.pageSize
      }).then((res) => {
        this.truckBellwetherTableDate = res.data;
        this.total = Number(res.headers['x-total-count']);
      });
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchCooperationTruckBellwetherToFilters();
    },
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchCooperationTruckBellwetherToFilters();
    }
  },
  mounted () {
    this.searchCooperationTruckBellwetherToFilters();
  },
  computed: {
    btns () {
      return this.$store.state.btns[this.$route.path] || [];
    },
    querys () {
      return this.$store.state.querys[this.$route.path + '#TruckLoadDriverCooperationTruckBellwether'] || [];
    }
  }
};
</script>
